package com.augn.controller;

import com.augn.entity.Post;
import com.augn.entity.Result;
import com.augn.service.IPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author augn
 * @since 2022-09-22
 */
@RestController
@RequestMapping("/post")
public class PostController {

    @Autowired
    private IPostService service;

    @PostMapping("/insertOne")
    public Result<?> insertOnePost(@RequestBody Post post) {
        return service.insertOnePost(post);
    }

    @DeleteMapping("/deleteOne/{id}")
    public Result<?> deleteOnePost(@PathVariable Integer id) {
        return service.deleteOnePost(id);
    }

    @PostMapping("/updateOne")
    public Result<?> updateOnePost(@RequestBody Post post) {
        return service.updateOnePost(post);
    }

    @GetMapping("/getOne/{id}")
    public Result<?> getOnePost(@PathVariable Integer id) {
        return service.getOnePost(id);
    }

    @PostMapping("/getPart")
    public Result<?> getPartPost(@RequestBody Post post,
                                  @RequestParam(required = false) Integer pageNum,
                                  @RequestParam(required = false) Integer pageSize) {
        return service.getPartPost(post,pageNum,pageSize);
    }
}
